package com.itheima.controller;


import com.itheima.pojo.Item;
import com.itheima.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("item")
public class ItemController {

    @Autowired
    private ItemService itemService;

    @RequestMapping("/showItem/{id}")
    public ModelAndView findById(ModelAndView modelAndView, @PathVariable("id") int id){
        Item item = itemService.findById(id);
        modelAndView.addObject("item",item);
        modelAndView.setViewName("item");

        return modelAndView;
    }
}
